package com.xiaochen.manager.controller;


import com.github.pagehelper.PageInfo;
import com.xiaochen.log.annotation.Log;
import com.xiaochen.log.enums.OperatorType;
import com.xiaochen.manager.service.BrandService;
import com.xiaochen.model.entity.product.Brand;
import com.xiaochen.model.vo.common.Result;
import com.xiaochen.model.vo.common.ResultCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 分类品牌(Brand)表控制层
 *
 * @author pinkhors
 * @since 2025-07-05 15:50:22
 */
@RestController
@RequestMapping("/admin/product/brand")
public class BrandController {

    @Autowired
    private BrandService brandService;

    /**
     * 分页查询
     */
    @Log(title = "品牌管理:查询",businessType = 0,operatorType = OperatorType.OTHER)
    @GetMapping("/selectByPage/{pageNum}/{pageSize}")
    public Result selectByPage(Brand brand,
                               @PathVariable Integer pageNum,
                               @PathVariable Integer pageSize){
        PageInfo<Brand> pageInfo = brandService.selectByPage(brand,pageNum,pageSize);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }

    /**
     * 通过主键查询单条数据
     */
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Long id){
        Brand brand = brandService.selectById(id);
        return Result.build(brand, ResultCodeEnum.SUCCESS);
    }

    /**
     * 根据name模糊查询数据
     */
    @GetMapping("/selectByName")
    public Result selectByName(@RequestParam String name){
        List<Brand> list = brandService.selectByName(name);
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }


    /**
     * 新增数据
     */
    @PostMapping("/save")
    public Result saveBrand(@RequestBody Brand brand){
        brandService.save(brand);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }


    /**
     * 编辑数据
     */
    @PutMapping("/updateBrand")
    public Result updateBrand(@RequestBody Brand brand){
        brandService.update(brand);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    /**
     * 删除数据
     */
    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Long id){
        brandService.deleteById(id);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    /**
     * 查询所有品牌
     */
    @GetMapping("/findAll")
    public Result findAll(){
        List<Brand> list = brandService.findAll();
        return Result.build(list,ResultCodeEnum.SUCCESS);
    }

}

